﻿using AutoMapper;
using Business.ReadAPI.Application.Breeds;
using Common.Domain;
using Common.Infrastructure.Repository;
using Common.Services;
using MediatR;

namespace Business.ReadAPI.Application.FarmEnterprises
{
    public class FarmQueryRequestHandler : IRequestHandler<FarmQueryRequestModel, APIResult>
    {
        private IBaseRepository<FarmEnterprise> farmRepository;
        private readonly IMapper mapper;
        public FarmQueryRequestHandler(IBaseRepository<FarmEnterprise> farmRepository, IMapper mapper)
        {
            this.farmRepository = farmRepository;
            this.mapper = mapper;
        }
        public Task<APIResult> Handle(FarmQueryRequestModel request, CancellationToken cancellationToken)
        {
            APIResult result = new APIResult();
            result.Code = EnumCode.SearchSuccess;
            result.Msg = "查询成功";

            var list = farmRepository.GetAll().FirstOrDefault();
            result.Data = list;

            return Task.FromResult(result);
        }
    }
    public class FarmQueryRequestModel:IRequest<APIResult>
    {
    }
    public class FarmQueryResponseModel
    {
        public int Id { get; set; }
        public string ProductCode { get; set; }
        /// <summary>
        /// 养殖场
        /// </summary>
        public string Farm { get; set; }
        /// <summary>
        /// 负责人
        /// </summary>
        public string Custodian { get; set; }
        /// <summary>
        /// 存栏数量
        /// </summary>
        public int FeedNum { get; set; }
        public string Creator { get; set; }
        public DateTime CreateTime { get; set; }
    }
}
